<template>
  <div class="app-container">
    <div class="detailsbody">
      <div class="top">编辑商品详情</div>
      <ul class="tiltes">
        <li class="active" v-if="commodity_details">基本信息</li>
        <li class="active" v-if="commodityd_escription">商品描述</li>
      </ul>
      <el-card class="detail_info" style="display:flex" v-if="commodity_details">
        <el-form :model="value" ref="productInfoForm" label-width="120px" size="small" class="el-form-table">
          <div class="detail_info-item">
            <div style="display:flex;margin-bottom:24px;">
              <span class="tilte" style="width:102px;">商品信息</span>
              <div class="line"></div>
            </div>
            <el-form-item label="商品名称" required prop="name">
              <el-input v-model="brand.name"></el-input>
            </el-form-item>
            <el-form-item label="商品图片" required prop="subTitle">
              <div class="tips">建议尺寸：1000*750像素，最多一张</div>
              <single-upload v-model="brand.pic"></single-upload>
            </el-form-item>
            <el-form-item label="商品展示图" required>
              <div class="tips">建议尺寸：160*160像素，最多1张</div>
              <div class="showcaseimg">
                <single-upload v-model="brand.picSquare"></single-upload>
                <!-- <single-upload v-model="brand.picSquare"></single-upload> -->
              </div>
            </el-form-item>
            <el-form-item label="商品价格" required>
              <el-input v-model="brand.price" placeholder="请输入内容"></el-input>
              <el-checkbox v-model="checked">促销活动</el-checkbox>
            </el-form-item>
            <el-form-item label="商品库存" required>
              <el-input v-model="brand.stock"></el-input>
            </el-form-item>
            <el-form-item label="数量规格" required>
              <el-input v-model="brand.amountSpecification" aria-placeholder="如：320ml/32颗装等"></el-input>
            </el-form-item>
            <el-form-item label="包装规格" required>
              <el-input v-model="brand.packSpecification" aria-placeholder="如：盒/件/瓶/袋等"></el-input>
            </el-form-item>
            <el-form-item label="成本价格" required>
              <el-input v-model="brand.costPrice"></el-input>填写成本可以帮助您统计利润数据
            </el-form-item>
          </div>
          <div class="detail_info-item">
            <div style="display:flex">
              <span class="tilte" style="width:102px;">物流信息</span>
              <div class="line"></div>
            </div>
            <el-form>
              <div class="details_set">
                <p>
                  <em>*</em>运费设置
                </p>
                <el-form-item>
                  <!-- 邮费类型：0统一邮费；1全国包邮；2本省包邮,外地统一邮费 -->
                  <el-radio-group v-model="brand.postageType">
                    <el-radio :label="0">统一邮费
                      <el-input v-model="brand.postage" style="width: 100px!important;height: 30px!important;"></el-input>
                    </el-radio>
                    <el-radio :label="1">全国包邮</el-radio>
                    <el-radio :label="2">本省包邮，外地统一邮费
                      <!-- <el-input v-model="brand.postage" style="width: 100px!important;height:30px!important;"></el-input> -->
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </div>
            </el-form>
          </div>
          <div class="detail_info-item">
            <div style="display:flex">
              <span class="tilte" style="width:102px;">销售说明</span>
              <div class="line"></div>
            </div>
            <el-form style="display:flex">
              <div class="details_set">
                <p>
                  <em>*</em>是否可退换
                </p>
                <div class="Replacement">
                  <!--  -->
                  <el-form-item>
                    <el-radio-group v-model="brand.isExchange">
                      <el-radio label="0">可退换</el-radio>
                      <el-radio label="1">不可退换</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
              </div>
              <div class="details_set">
                <p>
                  <em>*</em>积分使用
                </p>
                <div class="Integralusage">
                  <!--  -->
                  <el-form-item>
                    <el-radio-group v-model="brand.isUseIntegral">
                      <el-radio label="0">不可使用积分</el-radio>
                      <el-radio label="1">可使用积分（一积分兑换一元）</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
              </div>
            </el-form>
          </div>
          <el-form-item style="text-align: center">
            <el-button type="primary" @click="onSubmit('brandFrom')">保存</el-button>
            <el-button @click="cancel('brandFrom')">取消</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <div v-if="commodityd_escription" style="height:610px;">
        <div class="" style="height: 500px;border:none;">
          <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" style="height: 450px;border:none;"></quill-editor>
        </div>
        <el-form>
          <el-form-item style="text-align: center">
            <el-button type="primary" size="medium" @click="handlepreview()">预览</el-button>
            <el-button type="primary" size="medium" @click="handleSave()">保存</el-button>
            <el-button @click="handleCancel()">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import { quillEditor } from "vue-quill-editor";
import { Commoditydetails, updateBrand } from "@/api/product";
import SingleUpload from "@/components/Upload/singleUpload";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
const defaultBrand = {
  merchantId: 1,
  name: "",
  pic: "",
  picSquare: "",
  price: "",
  promotionStatus: 0,
  stock: "",
  amountSpecification: "",
  packSpecification: "",
  postageType: 0,
  isExchange: 0,
  isUseIntegral: 0
};
export default {
  name: "FuncFormsEdit",
  components: { SingleUpload, quillEditor },
  props: {
    isEdit: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      // value: Object,
      navIndex: 1, // 导航
      commodity_details: true,
      commodityd_escription: false,
      content: null,
      brand: Object.assign({}, defaultBrand),
      editorOption: {
        placeholder: "请输入"
        // theme: "bubble", // or 'bubble'
        // modules: {
        //   toolbar: {
        //     container: "#toolbar"
        //   }
        // }
      },

      imageUrl: "", //图像地址
      checked: false, //是否促销
      navList: [
        {
          id: 1,
          txt: "基本信息",
          status: "1"
        },
        {
          id: 2,
          txt: "商品描述",
          status: "2"
        }
      ],
      value: {
        name: "九转黄精丸【美肤排毒】"
      }
    };
  },
  created() {
    if (this.isEdit) {
      Commoditydetails(this.$route.query.id).then(response => {
        console.log(response.data, 2222222222);
        this.brand = response.data;
      });
    } else {
      this.brand = Object.assign({}, defaultBrand);
    }
  },
  methods: {
    switchTab(item) {
      this.navIndex = item.id;
      if (this.navIndex == 1) {
        this.commodity_details = true;
        this.commodityd_escription = false;
      } else {
        this.commodity_details = false;
        this.commodityd_escription = true;
      }
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    // 预览
    handlepreview() {},
    // 保存
    handleSave() {},
    //取消
    handleCancel() {},
    // getUEContent() {
    //   // 获取内容方法
    //   return this.editor.getContent();
    // },
    // destroyed() {
    //   this.editor.destroy();
    // }
    onSubmit(formName) {
      // this.$refs[formName].validate(valid => {
      // if (valid) {
      this.$confirm("是否提交数据", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        updateBrand(this.brand).then(response => {
          this.$refs[formName].resetFields();
          this.$message({
            message: "修改成功",
            type: "success",
            duration: 1000
          });
          this.$router.back();
        });
      });
      // } else {
      //   this.$message({
      //     message: "验证失败",
      //     type: "error",
      //     duration: 1000
      //   });
      //   return false;
      // }
      // });
    },
    cancel(formName) {
      this.$confirm("确认放弃本次编辑内容?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {})
        .catch(() => {
          this.$message({
            type: "success",
            message: "已取消操作!"
          });
          location.reload();
        });
    }
    // resetForm(formName) {

    // }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.app-container {
  background: #f1f1f1;
  min-height: 500px;
  .detailsbody {
    background: #fff;
    width: 100%;
    height: 100%;
    .tiltes {
      display: flex;
      font-size: 16px;
      font-family: AlibabaPuHuiTiR;
      border-bottom: 1px solid #cccccc;
      background: transparent;
      padding-left: 20px !important;
      line-height: 48px !important;
      box-sizing: border-box;
      padding: 0 !important;
      margin: 0 !important;
      li {
        width: 136px;
        text-align: center;
      }
      li.active {
        width: 136px;
        height: 4px;
        height: 48px;
        line-height: 48px !important;
        border-bottom: 4px solid rgba(96, 118, 255, 1);
        box-sizing: border-box;
      }
    }
    .el-card {
      box-shadow: none !important;
      border: none;
      .el-card__body {
        .detail_info-item {
          .flex {
            display: flex;
          }
          .title {
            font-size: 16px;
            width: 102px;
            font-family: AlibabaPuHuiTiM;
            color: rgba(0, 0, 0, 1);
          }
          .line {
            width: 1000px;
            padding-top: 12px;
            border-bottom: 2px solid #f1f1f1;
            // background: #f1f1f1;
          }
          .details_set {
            padding: 20px 0px;
            box-sizing: border-box;
            margin-left: 100px;
            .postage {
              input.el-input__inner {
                width: 100px !important;
                height: 30px !important;
              }
            }
            p {
              em {
                color: #ff0000;
                margin-right: 4px;
              }
            }
            span {
              margin-left: 4px;

              em {
                margin-right: 4px;
                font-style: normal;
              }
              b {
                color: #ccc;
              }
            }
          }
          .el-form-table {
            padding-top: 20px;
            margin-left: 80px;
            .tips {
              color: #999;
              font-size: 12px;
            }
          }
        }
      }
    }
  }
  .top {
    padding: 4px 25px 0;
    line-height: 34px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #f1f1f1;
    box-sizing: border-box;
    .edit {
      background: #169bd5;
      color: #fff;
      width: 73px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      border-radius: 4px;
    }
  }
}
</style>
